﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;
using Utilities.QuickSql;
using System.Globalization;
using System.IO;

namespace showcolat
{
    public partial class FormAccueil : Form
    {
        DBconnect db = new DBconnect();
        public FormAccueil()
        {
            InitializeComponent();
            Button BConnexion;
            this.Controls.Add(BConnexion = new Button
            {
                Name = "connexion",
                Location = new Point(this.Size.Width,50),
                AutoSize = true,
                Text = "Se connecter",
            });
            BConnexion.Click += new EventHandler(Connexion_Click);

            date_N.Text = DateTime.Now.ToString("D", CultureInfo.CreateSpecificCulture("fr-FR"));
            date_N1.Text = DateTime.Now.AddDays(1).ToString("D", CultureInfo.CreateSpecificCulture("fr-FR"));
            date_N2.Text = DateTime.Now.AddDays(2).ToString("D", CultureInfo.CreateSpecificCulture("fr-FR"));
        }

        public FormAccueil(int id_user)
        {
            InitializeComponent();
            int y = date_N.Location.Y+date_N.Size.Height+30;
            int i = 1;
            
            Button rech_serie;
            this.Controls.Add(rech_serie = new Button
            {
                Name = "Rechercher",
                Location = new Point(this.Size.Width, 50),
                AutoSize = true,
                Text = "Rechercher",
            });
            rech_serie.Click += new EventHandler(Rechercher_Click);

            string dateN = DateTime.Now.ToString("yyyy-MM-dd");
            date_N.Text = DateTime.Now.ToString("D", CultureInfo.CreateSpecificCulture("fr-FR"));
            string dateN1 = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");
            date_N1.Text = DateTime.Now.AddDays(1).ToString("D", CultureInfo.CreateSpecificCulture("fr-FR"));
            string dateN2 = DateTime.Now.AddDays(2).ToString("yyyy-MM-dd");
            date_N2.Text = DateTime.Now.AddDays(2).ToString("D", CultureInfo.CreateSpecificCulture("fr-FR"));
            Label lab_serie;

            /******affichage dateN********/
            List<Diffusion> listN = db.SelectSerie(dateN);
            foreach (Diffusion d in listN)
            {
                this.Controls.Add(lab_serie = new Label
                {
                    Name = d.IdSerie.ToString(),
                    AutoSize = true,
                    Location = new Point(100, y),
                    Text = d.TitreEpisode + " (Saison " + d.NumSaison + ")",
                    Font = new Font("Arial", 10)
                });
                y += 50;
                lab_serie.Click += new EventHandler(lbl_Click);
                i++;
            }
            /******affichage dateN1*****/
            y = date_N.Location.Y + date_N.Size.Height + 30;
            List<Diffusion> listN1 = db.SelectSerie(dateN1);
            foreach (Diffusion d in listN1)
            {
                this.Controls.Add(lab_serie = new Label
                {
                    Name = d.IdSerie.ToString(),
                    AutoSize = true,
                    Location = new Point(rect_N1.Location.X+15, y),
                    Text = d.TitreEpisode + " (Saison " + d.NumSaison + ")",
                    Font = new Font("Arial", 10)
                });
                y += 50;
                lab_serie.Click += new EventHandler(lbl_Click);
                i++;
            }
           
            /******affichage dateN1*****/
            y = date_N.Location.Y + date_N.Size.Height + 30;
            List<Diffusion> listN2 = db.SelectSerie(dateN2);
            foreach (Diffusion d in listN2)
            {
                this.Controls.Add(lab_serie = new Label
                {
                    Name = d.IdSerie.ToString(),
                    AutoSize = true,
                    Location = new Point(rect_N2.Location.X + 15, y),
                    Text = d.TitreEpisode +" (Saison "+ d.NumSaison+")",
                    Font = new Font("Arial", 10)
                });
                y += 50;
                lab_serie.Click += new EventHandler(lbl_Click);
                i++;
            }
            /******************************/
        }

       
        private void accueil_Load(object sender, EventArgs e)
        {
                System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
                ToolTip1.SetToolTip(this.lab_user, "Hello");
        }

        public void lbl_Click(object sender, EventArgs e)
        {
            
                Label l = (Label)sender;
                Form_description Desc = new Form_description(l.Name);
                Desc.ShowDialog();
                Desc.Location = new Point(lab_user.Location.X, lab_user.Location.Y + lab_user.Size.Height);                 
        }
        public void Connexion_Click(object sender, EventArgs e)
        {
            
            FormConnexion connexion = new FormConnexion(this);
            this.Hide();
            connexion.ShowDialog();
        }
        public void Rechercher_Click(object sender, EventArgs e)
        {
            Recherche recherche = new Recherche();
            recherche.ShowDialog();
        }

        private void menu_listeSerie_Click(object sender, EventArgs e)
        {
            fen_liste all_Serie = new fen_liste();
            all_Serie.ShowDialog();
        }

        public void modif()
        {
            lab_user.Text = "toto";
        }

        private void menu_quitter_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
